<template>
  <el-select v-model="model" value-key="id" v-bind="$attrs"> 
    <!-- 暂时不能理解 但是下拉闪烁的问题是解决的 -->
    <template #label="option">{{ option.value['label'] }}</template>
    <el-option v-for="item in seletOptions" :key="item[sign.id]" :label="item[sign.label]" :value="sign.value? item : item[sign.value]"></el-option>
  </el-select>
</template>

<script lang="ts" setup>
// vue3 写的真好
import { onMounted, computed } from 'vue'
import { SelectPropsInterface } from './types'

const { store, sign } = defineProps<SelectPropsInterface>()
// 内置的方法 便捷的获取v-model的值
const model = defineModel({required: true})

// 请求
onMounted(async ()=>{
  if (store.autoload) {
    await store.searchData()
  }
})
// 获取值
const seletOptions = computed(()=>{
  return store.view.value.data || []
})

</script>